/**
 * Selling Partner API for Solicitations
 * With the Solicitations API you can build applications that send non-critical solicitations to buyers. You can get a list of solicitation types that are available for an order that you specify, then call an operation that sends a solicitation to the buyer for that order. Buyers cannot respond to solicitations sent by this API, and these solicitations do not appear in the Messaging section of Seller Central or in the recipient's Message Center. The Solicitations API returns responses that are formed according to the <a href=https://tools.ietf.org/html/draft-kelly-json-hal-08>JSON Hypertext Application Language</a> (HAL) standard.
 *
 * The version of the OpenAPI document: v1
 *
 *
 * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
 * https://openapi-generator.tech
 * Do not edit the class manually.
 *
 */

import { ApiClient } from '../ApiClient.js'
import { CreateProductReviewAndSellerFeedbackSolicitationResponse } from '../model/CreateProductReviewAndSellerFeedbackSolicitationResponse.js'
import { GetSolicitationActionsForOrderResponse } from '../model/GetSolicitationActionsForOrderResponse.js'
import { SuperagentRateLimiter } from '../../../helper/SuperagentRateLimiter.mjs'
import { DefaultRateLimitFetcher } from '../../../helper/DefaultRateLimitFetcher.mjs'

/**
* Solicitations service.
* @module solicitations_v1/api/SolicitationsApi
* @version v1
*/
export class SolicitationsApi {
  // Private member stores the default rate limiters
  #defaultRateLimiterMap

  /**
    * Constructs a new SolicitationsApi.
    * @alias module:solicitations_v1/api/SolicitationsApi
    * @class
    * @param {ApiClient} [apiClient] Optional API client implementation to use,
    * default to {@link ApiClient#instance} if unspecified.
    */
  constructor (apiClient) {
    this.apiClient = apiClient || ApiClient.instance
    this.initializeDefaultRateLimiterMap()
  }

  /**
     * Initialize rate limiters for API operations
     */
  initializeDefaultRateLimiterMap () {
    this.#defaultRateLimiterMap = new Map()
    const defaultRateLimitFetcher = new DefaultRateLimitFetcher()
    const operations = [
      'SolicitationsApi-createProductReviewAndSellerFeedbackSolicitation',
      'SolicitationsApi-getSolicitationActionsForOrder'
    ]

    for (const operation of operations) {
      const config = defaultRateLimitFetcher.getLimit(operation)
      this.#defaultRateLimiterMap.set(operation, new SuperagentRateLimiter(config))
    }
  }

  /**
     * Get rate limiter for a specific operation
     * @param {String} operation name
     */
  getRateLimiter (operation) {
    return this.#defaultRateLimiterMap.get(operation)
  }

  /**
     * Sends a solicitation to a buyer asking for seller feedback and a product review for the specified order. Send only one productReviewAndSellerFeedback or free form proactive message per order.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 5 |  The &#x60;x-amzn-RateLimit-Limit&#x60; response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     * @param {String} amazonOrderId An Amazon order identifier. This specifies the order for which a solicitation is sent.
     * @param {[String]} marketplaceIds A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
     * @return {Promise<CreateProductReviewAndSellerFeedbackSolicitationResponse>}
     */
  createProductReviewAndSellerFeedbackSolicitationWithHttpInfo (amazonOrderId, marketplaceIds) {
    const postBody = null

    // verify the required parameter 'amazonOrderId' is set
    if (amazonOrderId === undefined || amazonOrderId === null) {
      throw new Error("Missing the required parameter 'amazonOrderId' when calling createProductReviewAndSellerFeedbackSolicitation")
    }

    // verify the required parameter 'marketplaceIds' is set
    if (marketplaceIds === undefined || marketplaceIds === null) {
      throw new Error("Missing the required parameter 'marketplaceIds' when calling createProductReviewAndSellerFeedbackSolicitation")
    }

    const pathParams = {
      amazonOrderId
    }
    const queryParams = {
      marketplaceIds: this.apiClient.buildCollectionParam(marketplaceIds, 'csv')
    }
    const headerParams = {
    }
    const formParams = {
    }

    const contentTypes = []
    const accepts = ['application/hal+json']
    const returnType = CreateProductReviewAndSellerFeedbackSolicitationResponse

    return this.apiClient.callApi('SolicitationsApi-createProductReviewAndSellerFeedbackSolicitation',
      '/solicitations/v1/orders/{amazonOrderId}/solicitations/productReviewAndSellerFeedback', 'POST',
      pathParams, queryParams, headerParams, formParams, postBody,
      contentTypes, accepts, returnType, this.getRateLimiter('SolicitationsApi-createProductReviewAndSellerFeedbackSolicitation')
    )
  }

  /**
     * Sends a solicitation to a buyer asking for seller feedback and a product review for the specified order. Send only one productReviewAndSellerFeedback or free form proactive message per order.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 5 |  The &#x60;x-amzn-RateLimit-Limit&#x60; response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     * @param {String} amazonOrderId An Amazon order identifier. This specifies the order for which a solicitation is sent.
     * @param {[String]} marketplaceIds A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
     * @return {Promise<CreateProductReviewAndSellerFeedbackSolicitationResponse>}
     */
  createProductReviewAndSellerFeedbackSolicitation (amazonOrderId, marketplaceIds) {
    return this.createProductReviewAndSellerFeedbackSolicitationWithHttpInfo(amazonOrderId, marketplaceIds)
      .then(function (response_and_data) {
        return response_and_data.data
      })
  }

  /**
     * Returns a list of solicitation types that are available for an order that you specify. A solicitation type is represented by an actions object, which contains a path and query parameter(s). You can use the path and parameter(s) to call an operation that sends a solicitation. Currently only the productReviewAndSellerFeedbackSolicitation solicitation type is available.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 5 |  The &#x60;x-amzn-RateLimit-Limit&#x60; response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     * @param {String} amazonOrderId An Amazon order identifier. This specifies the order for which you want a list of available solicitation types.
     * @param {[String]} marketplaceIds A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
     * @return {Promise<GetSolicitationActionsForOrderResponse>}
     */
  getSolicitationActionsForOrderWithHttpInfo (amazonOrderId, marketplaceIds) {
    const postBody = null

    // verify the required parameter 'amazonOrderId' is set
    if (amazonOrderId === undefined || amazonOrderId === null) {
      throw new Error("Missing the required parameter 'amazonOrderId' when calling getSolicitationActionsForOrder")
    }

    // verify the required parameter 'marketplaceIds' is set
    if (marketplaceIds === undefined || marketplaceIds === null) {
      throw new Error("Missing the required parameter 'marketplaceIds' when calling getSolicitationActionsForOrder")
    }

    const pathParams = {
      amazonOrderId
    }
    const queryParams = {
      marketplaceIds: this.apiClient.buildCollectionParam(marketplaceIds, 'csv')
    }
    const headerParams = {
    }
    const formParams = {
    }

    const contentTypes = []
    const accepts = ['application/hal+json']
    const returnType = GetSolicitationActionsForOrderResponse

    return this.apiClient.callApi('SolicitationsApi-getSolicitationActionsForOrder',
      '/solicitations/v1/orders/{amazonOrderId}', 'GET',
      pathParams, queryParams, headerParams, formParams, postBody,
      contentTypes, accepts, returnType, this.getRateLimiter('SolicitationsApi-getSolicitationActionsForOrder')
    )
  }

  /**
     * Returns a list of solicitation types that are available for an order that you specify. A solicitation type is represented by an actions object, which contains a path and query parameter(s). You can use the path and parameter(s) to call an operation that sends a solicitation. Currently only the productReviewAndSellerFeedbackSolicitation solicitation type is available.  **Usage Plan:**  | Rate (requests per second) | Burst | | ---- | ---- | | 1 | 5 |  The &#x60;x-amzn-RateLimit-Limit&#x60; response header returns the usage plan rate limits that were applied to the requested operation, when available. The table above indicates the default rate and burst values for this operation. Selling partners whose business demands require higher throughput may see higher rate and burst values than those shown here. For more information, see [Usage Plans and Rate Limits in the Selling Partner API](https://developer-docs.amazon.com/sp-api/docs/usage-plans-and-rate-limits-in-the-sp-api).
     * @param {String} amazonOrderId An Amazon order identifier. This specifies the order for which you want a list of available solicitation types.
     * @param {[String]} marketplaceIds A marketplace identifier. This specifies the marketplace in which the order was placed. Only one marketplace can be specified.
     * @return {Promise<GetSolicitationActionsForOrderResponse>}
     */
  getSolicitationActionsForOrder (amazonOrderId, marketplaceIds) {
    return this.getSolicitationActionsForOrderWithHttpInfo(amazonOrderId, marketplaceIds)
      .then(function (response_and_data) {
        return response_and_data.data
      })
  }
}
